import 'package:flutter/material.dart';
import 'package:flutterapp/utils/fade_route.dart';

import 'animation_9_2_2_custom.dart';

/// @date 2020/08/11  15:51
/// @author 程志强
/// @des 自定义动画

class CustomAnimation extends StatefulWidget {
  @override
  _CustomAnimationState createState() => _CustomAnimationState();
}

class _CustomAnimationState extends State<CustomAnimation> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("自定义动画切换页面"),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text("切换路路由"),
              onPressed: () {
                Navigator.push(
                    context,
                    PageRouteBuilder(
                        // 动画时间为500毫秒
                        transitionDuration: Duration(milliseconds: 500),
                        pageBuilder: (BuildContext context, Animation animation,
                            Animation secondaryAnimation) {
                          return FadeTransition(
                            // 使用渐隐渐入过渡
                            opacity: animation,
                            child: CustomAnimation2(),
                          );
                        }));
              },
            ),
            RaisedButton(
              child: Text("切换路路由2"),
              onPressed: () {
                Navigator.push(context, FadeRoute(builder: (context) {
                  return CustomAnimation2();
                }));
              },
            ),
          ],
        ),
      ),
    );
  }
}
